﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Data.Linq;

namespace BGCMS.Models
{
    /// <summary>
    /// A partial model class used for integrating validation and business rule logic
    /// </summary>
    public partial class Keyword
    {
        /// <summary>
        /// Indicates whether the Keyword object has any active RuleViolations
        /// </summary>
        public bool IsValid
        {
            get { return (KeywordGetRuleViolations().Count() == 0); }
        }

        /// <summary>
        /// Causes our validation and business rules to be evaluated.
        /// </summary>
        /// <returns>Returns a sequence of KeywordRuleViolation objects that provide more 
        /// details about any rule errors.</returns>
        public IEnumerable<KeywordRuleViolation> KeywordGetRuleViolations()
        {
            if (String.IsNullOrEmpty(Title))
                yield return new KeywordRuleViolation("Það vantar efnisflokk", "Title");
            yield break;
        }
    }

    /// <summary>
    /// A helper class that provides more details about a rule violation
    /// </summary>
    public class KeywordRuleViolation
    {

        public string KeywordErrorMessage { get; private set; }
        public string KeywordPropertyName { get; private set; }

        public KeywordRuleViolation(string errorMessage, string propertyName)
        {
            KeywordErrorMessage = errorMessage;
            KeywordPropertyName = propertyName;
        }
    }
}